ARC031 B - 埋め立て
提出
code: python
print(a)
# oの置き換えはどうするか、100通り試す?
# 島が四つでもokの場合がある
# スタートをどこにするか
# 通過したところをxにして全部xになっていたらOK
解答
code: python
import copy
init_field = list(list(input()) for _ in range(10))
un_stepped_field = list(list(False for _ in range(10)) for _ in range(10))
def count_continent(field):
continent_count = 0
for line in field:
continent_count += line.count("o")
return continent_count
def count_stepped_field(pre_counted_field):
stepped_count = 0
for line in pre_counted_field:
stepped_count += line.count(True)
return stepped_count
def search(y, x):
# マップ外
if x < 0 or x >= 10 or y < 0 or y >= 10:
return
# 海
return
# 探索済み
return
# ここで四方に探索
search(y+1, x)
search(y-1, x)
search(y, x+1)
search(y, x-1)
for i in range(10):
for j in range(10):
stepped_field = copy.deepcopy(un_stepped_field)
field = copy.deepcopy(init_field)
# 埋立地作る
# 探索開始
search(j, i)
# 探索したマスの数が陸地の数と一致すれば題意を満たす
if count_stepped_field(stepped_field) == count_continent(field):
print("YES")
exit()
print("NO")
テーマ
メモ
提出
AC
code: python
import copy
def resolve(land):
visited = [False * 10 for _ in range(10)] def dfs(nowi, nowj):
for n in range(4):
if nowi + nextin < 0 or nowi + nextin > 9 or nowj + nextjn < 0 or nowj + nextjn > 9 or visited[nowi + nextin][nowj + nextjn] or land[nowi + nextin][nowj + nextjn] == "x": continue
else:
visited[nowi + nextin][nowj + nextjn] = True dfs(nowi + nextin, nowj + nextjn) flag = True
for i in range(10):
if not flag:
break
for j in range(10):
flag = False
dfs(i, j)
break
target = 0
res = 0
for i in range(10):
for j in range(10):
target += 1
res += 1
return target == res
for i in range(10):
for j in range(10):
landc = copy.deepcopy(land)
if resolve(landc):
print("YES")
exit()
print("NO")